Skip to content

trystero: port to Trystero 0.27.0 (draft, merges after its interop) - #10

Draft
pinhopro wants to merge 62 commits into
mainfrom
port/trystero-0.27
Draft

pinhopro wants to merge 62 commits into
mainfrom
port/trystero-0.27

Conversation

@pinhopro

Copy link
Copy Markdown
Contributor

Phase 1 of the port of webcpp::trystero to Trystero 0.27.0 (change trystero-0-27 in webcpporg/proposals, design D1: one long-lived branch, merged once after its interop in Phase 2). This draft is not interoperable with Trystero 0.27.0 yet and must not merge before Phase 2.

What Phase 1 changes, each task proven against vectors recorded from 0.27.0's own code:

  • Topics, ids, relays and room keys are 0.27.0's: base64url SHA-256 topic paths, unbiased base62 ids, 0.27.0's relay list in its seeded order, SHA-256 or PBKDF2 then HKDF room keys, HMAC auth tokens read strictly.
  • Signals are sealed with AES-256-GCM, a 12-byte IV and the signal's AAD, over webcpp::hash and webcpp::crypto; the backend keeps no sealer or randomness of its own, and PBKDF2 runs off the room's thread.
  • Nostr is 0.27.0's: a signer per room over webcpp::crypto's secp256k1, kinds by FNV-1a, subscriptions since a minute ago in chunks of 250, relays retired, cooled down and probed.
  • The action wire is version 3 with wide bulk frames, byte-identical to 0.27.0's frames; frames of an action not made are dropped or rejected as 0.27.0 does.
  • Listeners are added with on_ and return a subscription; a room reports 0.27.0's error codes through on_error with their context; a room knows its users and their peers and sends to either; relays go offline and online on request; the options 0.27.0 removed are gone.
  • The library wipes its secrets with its own wipe and no longer uses another library's detail namespace.
  • The pages say what Phase 1 changed, marked "not interoperable before Phase 2".

Known red check: the docs check fails until webcpp::hash's reference configuration is fixed (its config.hpp defines WEBCPP_HASH_HAS_OPENSSL under __MRDOCS__, which its Emscripten #error refuses); trystero's half is done. The interop and oracle lanes stay off until Phase 2.6. What Phase 2 inherits is listed in the change's reference/STATUS.md.

A second known red check: the lint's clang-tidy flags webcpp::crypto's secp256k1 canary (backends/secp256k1.hpp:66, bugprone-dynamic-static-initializers) in trystero's units that include it; the fix is webcpp::crypto's. trystero's own sources pass the whole lint.

Verified locally: native clang and gcc-15 and Emscripten (tests and examples), the macOS and Linux lints (only the crypto finding above), and the MSVC 14.3 and 14.5 lanes (only the Wine artifacts the lane already lists).

R added 30 commits November 20, 2026 23:09
…ed from its own code, and links webcpp::hash and webcpp::crypto
…eded order, and peer and user ids derive from a compact key
…PBKDF2 then HKDF with one, and its auth tokens are HMACs read strictly
…t asserted, and the room-key helpers use the caller's memory
… 12-byte IV and the signal's AAD, in base64url
… thread, and the backend keeps no sealer and no randomness of its own
…e is tested, and room_test builds with libstdc++
…inds by FNV-1a, subscriptions since a minute ago, and relays retired, cooled and probed
…ened relay resubscribed without a new warm-up, and the retry, cooldown and signer paths tested
…eers, frames of an action not made are dropped or rejected as 0.27.0 does, and an offer's chunk width is typed

- detail/action_wire.hpp: drain() marks the transfers it accepts while it walks incoming_, then
  delivers and sends the accepted frames, looking each peer up again; a control frame into a
  channel over 1 MiB kicked the peer, whose clear_peer erased the node the loop stood on.
- Ruling R14: an inline frame of an action the room has not made is dropped and an offer of one
  rejected at once with "unregistered action"; the ring of 32 per action and peer holds messages of
  an action made but not listening; the cross-name bound of 64 per peer is gone. The wire asks
  has_action and has_listener; a room's made action always listens (async_receive's queue).
- protocol/action_wire.hpp: append_offer and encode_offer take a chunk_width, which a memory
  resource pointer cannot silently convert to.
- Tests: a_transfer_accepted_into_a_full_channel_kicks_its_sender (shared, a real room; RED as a
  segfault and an ASan heap-use-after-free in drain), frames_of_an_action_not_made_are_dropped_or_rejected,
  a cleared two-peer case and a ring per action in room_test, the reason of a narrow chunk on a
  wide transfer, and action_frames_match reading ids, reasons and the response payload from the
  recorded frames.
…leave clears listeners and drops posted joins, a name keeps its first action kind (error::action_redefined), refusal reasons are cut and read as 0.27.0's, and lifetime tests
…sage, the decrypt report pacer is proven to refresh a key it reads, an offer reset allows a new connect-failure report, a message posted before a leave goes with the room, the relay-failure report stops when its sink left the room, the answer stage and turn_configured are tested and documented, and failed_open takes a stage
…eam of the app instead of a public backend call, users() and peers() look up by string_view, a send to a user documents that it reaches only active peers, a user's peers are listed in the order they became active, the user table asserts its two maps agree, and a replay of a two-peer user is tested
…ain, the last user's release ends the page watch, the page watch is the member destroyed first, the handshake timeout seam says it lasts until set again, the relay connectivity docs record that visibilitychange is not followed and that a value outside the enum is taken as online, the backoff edge cases of offline and online are tested, and the differences page keeps its rows and programs consistent
…ger reaches into webcpp::crypto's detail namespace
…sword, the reference gets BearSSL, and the doc comments pass the reference's check

- The app's own copy of the password is wiped when the app is destroyed, so every copy is wiped
  before it is freed (test the_password_is_wiped_before_it_is_freed scans every freed block).
- The doc reference reads the rooms with BearSSL, Emscripten's GCM default, in place of the
  native gcm-default's OpenSSL (<webcpp-trystero-reference>on, rooms-gcm in build.jam); what
  still fails it is webcpp::hash's MrDocs configuration, the hash stream's fix.
- Sixteen doc comments the reference's doc_comments.py refused are fixed (one-sentence briefs,
  a @tparam, a brief for detail::listeners).
- The class docs of room, action and request_action say they are not interoperable before
  Phase 2 and name distinct peer ids; open's doc names the cipher's error; room_keys.hpp's
  wipe comment names trystero's own wipe.
- The backend's destructor and the platform page say a program destroys the backend before its
  io_context.
- crypto_layer_test selects its seal vector by its fields, allocation_test checks OpenSSL's
  count against one measured seal and open, and the PBKDF2 test proves natively that the
  io_context runs only the completion.
…es, a completion after the call on the io_context, and no longer claims where the iterations run
…ce, so that libstdc++'s std::advance found by ADL no longer breaks the build with gcc
… named helpers, a posted hand-over called through a pointer, every boost::system::result [[nodiscard]], the entropy lines say why, the Doc Comments, the recorder's licence notice and the Jam comments fixed

The room's start makes its wire, signaling and strategy in helpers of their own; the action
wire's drain takes the ready inline frames, accepts the next transfer and delivers in three;
without_lone_surrogates reads an escape through unicode_escape_at and hex_digit_value. A
message posted to an action's listeners hands over through a member pointer, so that
misc-no-recursion sees no cycle through Asio's post, as the WebSocket session does. Math
parentheses, an unsigned header byte, const node handles, trailing commas and one
NOLINTNEXTLINE for the listener copy call_first must hold. The tests split
action_frames_match and an_answerers_signals_are_trysteros into helpers, take strings by
reference, bind the clock reading of the fluent chain, and capture a pointer where a closure
copied a string.
… not through std::to_string, so that the room keys a password derives allocate nothing globally under MSVC's debug containers
R added 29 commits November 22, 2026 14:38
…1 keypair::generate

signer::generate returns keypair::generate's key pair turned into a signer as from_secret does; max_key_draws and the draw loop are gone (Phase 1's R11).
…e inline size bound and document the reserved phase
…n takes 64 KiB messages, as 0.27.0 sends it

backend::peer_connection::max_message_size reports the SCTP transport's
largest message; peer_link's max_bulk_frame_bytes is 0.27.0's getter and the
action wire offers a transfer wide when it is 64 KiB. The platform backend
reads it from the applied remote description (a=max-message-size, RFC 8841,
within webcpp::webrtc's 256 KiB), as libdatachannel and the W3C compute it;
the memory network says 256 KiB unless a test sets less or nothing.

The platform data channel's pending frames cover only the gap before the
room's link takes the channel, under the link's own bounds (64 frames of at
most 17 KiB, now protocol constants), without a timer of its own.
… from webcpp::webrtc, and a refused send closes the channel

The platform peer connection's max_message_size() is webcpp::webrtc's
peer_connection::max_message_size() (natively rtcGetRemoteMaxMessageSize,
in a page sctp.maxMessageSize), the limit its channels' sends check; the
remote SDP parser and its tests are gone. A frame the platform channel
refuses closes the channel, which reports the close, so a transfer ends
with the peer instead of stalling to its timeout; the memory network's
send_limit refuses likewise (room_test). platform_peer_connection_test
sends a wide chunk, a message of exactly the reported size and one byte
more over the native connection; the page test reads the stand-in's sctp
directly, with no polling wait. The design notes say why a channel no link
takes is bounded by its negotiation side's lifetime.
… and user keys, and a user identity is created, imported and exported as 0.27.0's

The app draws a P-256 endpoint key (webcpp::crypto's p256, linked through
/webcpp/crypto//p256-default) and derives its peer id from the compact
public key; its user is app_config::identity or an ephemeral user identity
it makes. protocol/ecdsa.hpp signs with low S and verifies refusing a high
S, and holds trystero's only calls of webcpp::crypto's P-256 sign and
verify. protocol/identity.hpp reads and writes the user key text as
0.27.0's tryParsePrivateJwk and buildExtractableUserIdentity do, wiping
every buffer that held the scalar, and writes the user-proof payload.
identity.hpp adds user_identity, create_user_identity,
import_user_identity (with error::invalid_user_identity and 0.27.0's
self-test) and export_user_identity. An app whose endpoint key or user key
cannot be made reports identity_failed on each room it joins, after the
join, then the room ends without reaching a relay, as 0.27.0's failSetup.

The test seam app_access::make takes an endpoint scalar in place of a
self id; the tests name their apps by labels and order them by derived
ids (endpoint_scalar, peer_id_of, ordered_labels, label_beside).
…helpers, and tests prove a user key's scalar is wiped and a user key failure is reported.

- identity.hpp: detail::make_p256_key, make_endpoint_identity and
  user_identity_access::make(scalar, memory); app_impl and the tests' peer_id_of
  use them, so identity.hpp and protocol/ecdsa.hpp are the only P-256 call sites.
- app_access::make gains a user scalar (zero fails); room test
  a_user_key_that_cannot_be_made_reports_identity_failed.
- crypto_layer test user_key_buffers_are_wiped: a watching resource, also the
  default one, finds no fixture scalar in any freed block.
- user_identity has copy operations only: a move copies, never leaves it empty.
- Docs: identity_failure notes 0.27.0's own-message rule, usage.adoc's
  invalid_user_identity row, missing @param/@return, stale test comments,
  platform tests assert the id order they rely on.
….0's bounds, and a high S is refused before any verification

detail::identity_cache holds an app's key records (4,096) and verified signatures (8,192, 2 MiB, payloads of at most 4,096 bytes), least recently used first out, in the app's resource, as 0.27.0's getVerifiedPubKeyRecord, verifyWithP256, verifyPeerIdKey and verifyUserIdKey keep and check them. A point is read through the new protocol::p256_public_key seam helper, and parse_compact_public_key takes the resource of its buffers.
…s bounds and the skipped verification of a cached answer are proven without thousands of real signatures.
…ts left are hang guards, so a loaded machine cannot fail a case that waits for something that must happen

A refused-chunk case also watches the peers' departure as events, since the apps meet again and no peers is a transient state.
…ed machine, since their fixed drains became deterministic and their wall-clock waits are hang guards

allocation_test drains with poll until empty instead of fixed run_for windows (counts unchanged), memory_backend_test settles instead of 100 ms negative windows, timer_test runs its io_context to completion, and the positive waits of allocation, app_impl, peer_link, memory_backend, platform_websocket and platform_peer_connection use a 120 s hang guard.
…0.27.0's, and each side's run of it verifies the other's JS signatures

protocol/handshake.hpp: the DTLS fingerprints of a description, the three
steps as 0.27.0 writes them, their reading without the key checks, and the
transcript. detail/identity_handshake.hpp: createIdentityHandshake's run as a
synchronous step machine whose keys and signatures go through the identity
cache and the P-256 seam. The handshake manager's reasons name the protocol's.
Tested against the fixture's handshake cases: the C++ responder and initiator
meet the recorded JS sides, and each recorded failure fails with its reason.
…nother transcript's, and the shared reasons move to a light header
… binds its endpoint and user keys to both DTLS fingerprints, and users are the ids it verified

- The signaling keeps each side's last local description and the last one
  applied as remote, and hands both to the room with the connection; the
  room keeps their DTLS fingerprints with the peer (design D20).
- The handshake manager's steps are one identity_handshake per peer run,
  fed @_hsdata through next_message; its nonce bytes are drawn from the
  backend for every run; the verified identity is kept in the peer's state
  before done(""), as 0.27.0's onVerified; a failed run is reported once as
  handshake_failed with 0.27.0's reason, and the peer is told to leave.
- The initiator is the lower id in UTF-16 code unit order (utf16_less moves
  to protocol/text.hpp).
- A peer's user is the id its handshake verified: app_impl's user_resolver,
  resolve_users_with and user_of, memory_network's assign_user and
  user_of, and test::group_users are gone; the users cases use two apps
  that import one user_identity.
- The memory backend writes "mem:<id>" and an a=fingerprint:sha-256 line.
- identity_handshake's step 3 signatures are made in the run's resource (a
  pmr copy took the default one; caught by allocation_test).
…frames and a failed run sends its farewell and closes, and the room fails closed without a verified identity

- room_test: check_pending_pair asserts, while a handshake is pending, empty peers()
  and users() on both sides, no user frame sent either way, and no injected user
  frame delivered; used by the forged-step cases and by the leave cases, now held at
  step 2 (neither side verified) and at step 3 (only the initiator verified).
- The forged-step cases count B's @_leave (dropped on its way) and check that B's
  end of the connection closes after the failure.
- The nonce check proves each second-meeting nonce is the UUID of a 16-byte draw of
  the backend's randomness (memory_network::on_random).
- room.hpp: a run whose peer went ends as disconnected, never verified; activate
  refuses a peer without a verified identity; run_identity fails closed on an app
  without its identity.
- signaling_test: connected_carries_the_descriptions_applied (a refused answer,
  then a new negotiation whose connected call carries its own descriptions).
- AGENTS.md: reflowed paragraph, on_random noted.
… user id and refused with room_full, as 0.27.0's rooms are

room_options::max_users (absent: unbounded; 0 or above 2^53 - 1 refused by app::join with the appended error::invalid_max_users). The room ports room.ts's admission: users counted are its own, the active peers' and the admissions under way (reservedAdmissionUsers); the responder's ready frame is deferred with max_users; local_passed, admit and activate refuse a full candidate with @_hsready {"ok":false,"err":"room full"}, then the peer goes after destroyAfterFlush's 40-150 ms, without reannouncing. Refused users are remembered (256, LRU) and the signaling's new should_connect hook (shouldConnectPeer) skips them while the room is full. A refusal received from a pending peer reports room_full with its id, deferred until the peer is verified as 0.27.0's deferredReady.
…directions of a full room are pinned by tests, and the review's smaller findings are fixed
…first announcement, and pings as 0.27.0 pings, through a request

- peer_error: the action wire's fail_peer reports a room_error peer_error with the reason
  (0.27.0's handleData words for each undecodable frame) and the peer id, then kicks the peer;
  a peer not in the room is ignored (hasAnyPeer).
- banned: an @_hsready {"ok":false,"err":"peer banned"[,"reason":r]} from a pending peer reports
  banned, "peer banned" or "peer banned: r", r kept when a text of at most 512 UTF-16 units;
  the peer is told to leave and goes, flushed and unannounced. A refusal before verification
  waits for it (deferredReady), now for both refusals.
- relay_failed, second path: when no relay's first announcement was written and every relay
  failed to boot or settled its first announcement, once per room with the boot path. An
  announcement fails when it cannot be signed or its socket drops it: backend::websocket::send
  now returns whether the text was taken; the memory backend gains fail_publish(url).
- @_ping is an internal request action answered "" through @_response; @_pong is gone; a ping
  goes through the room's requests, its target a peer or a user.
- An offer of @_response that answers no request of ours is rejected "unexpected response"
  (receiveScope), an inline one dropped.
…umented as the port's own, and the new peer, ban and ping paths are tested and documented
…ished packages equal the pinned source, and the twins speak 0.27.0

The oracle runs @trystero-p2p/core and nostr 0.27.0 (pinned in package.json
and package-lock.json) and computes only the sections protocol_test and
signaling_test read: event messages and ids through createEvent, signal
texts, duplicate keys through 0.27.0's signal handler and Nostr strategy,
the answerer's signals sealed with their AAD, and payload texts. Its output
moves to test/fixtures/oracle/expected.json, so that the vectors fixture is
no cases output. generated-vectors (vectors.py) runs record_0_27.mjs --dist
over the published packages with the fixture as previous output and must
write it byte for byte; it joins the oracle lane.

A signal is written as 0.27.0 writes it, {peerId, offerId, <kind>}: the
answerer's 0.26 order and the passive member go. The twins use 0.27.0's
API and their outputs are recorded again; diff_relay_config is retired,
since a twin observing each room's relays prints what the C++ program
prints.
…efuses it, and the oracle shows 0.27.0 refusing each such envelope

read_signal now applies 0.27.0's rules: a peer id of 20 base62 characters,
an offer id of 1 to 64 characters of [0-9A-Za-z_.~:!-], required with an
offer, answer or candidate and refusing whenever present and invalid, and
offer/answer/candidate bounds in UTF-16 code units (64 Ki, 64 Ki, 4,096).
max_peer_id_bytes goes (peer_id_size); the bounds are renamed *_chars.

The oracle gains the signal_envelopes cases (26 signals through 0.27.0's
signal handler, 8 answers through its whole room) and records 0.27.0's
read-back of signal_texts; tests that relied on looser ids now use valid
ones. Docs updated; the page.mjs header is rewrapped and the oracle names
its event-order assumption.
…cess, on every interop scenario, and the oracle and interop lanes are on

The interop driver, its pages and both C++ peers are rewritten for 0.27.0:
the two C++ peers share one peer (interop/peer_room.hpp) whose parameters and
events js.html mirrors, and run.mjs runs the twelve scenarios of the plan on
each lane (ids and messages, signatures, 1 MiB each way, passwords, imported
identities, one user of two C++ apps, max_users both ways, requests and pings,
leaves, a forged user signature, a mesh, relay connectivity), then the C++
peer's own relay robustness. The 0.26.0 scenarios of the shared connection,
the signal watcher and the self-chosen id order are gone; a C++ peer's id is
ordered against a page's through its endpoint key's label, which the driver
derives with 0.27.0's own code. The oracle Jamfile's explicit line is removed,
platform_page_entropy is added (explicit: webcpp::crypto's random_device lets
a throwing crypto.getRandomValues through, P2-R16), and the pages lose their
"not interoperable before Phase 2" clauses.
…de offering, the malformed candidate and the flood ported to 0.27.0, and the last non-interop clauses gone

relay_connectivity sees the relay's side (subscriptions closed offline, a new subscription online, a peer started offline subscribing to nothing); wide_transfers checks 64 KiB frames both ways on the page's data channel; ids_and_messages runs with the C++ id below and above the page's; the malformed candidate is sealed with 0.27.0's encrypt for the C++ peer's offer while the relay holds the page's answer; the flood sends unsealed offers and announcements from fresh ids with 0.27.0's createEvent and bounds negotiations, connections and decrypt_failed reports; passwords and the forger count their reports; the Chrome start and CDP calls are bounded only by the hang guard; README, AGENTS.md, usage, differences, guarantees and testing updated.
…nd the changelog has its lines

Every page, the README and AGENTS.md describe the library as it is, interoperable with Trystero 0.27.0: identities, the signed handshake, one connection per room and peer, max_users and the room errors with their emitters; the shared connection's prose is gone. The differences page gains the rows the port's tasks recorded, the guarantees cite tests that exist, the migration from trystero 0.1.0 is in the usage page and the README, and the changelog's Unreleased holds the port's lines within ten. Six Doc Comment briefs of two sentences are split, and pmr_bytes says its payload is moved.
…ws, requires every report, and the forger reads reports before the log
…negotiate again, a disconnection's grace is not extended, and the pages say what an unexpected answer, identity-failed and an unlimited connection do
…::pmr::string's holder, views cut without throwing, the long transfer and handshake paths split, and the const, trailing comma and widening findings fixed
…: long cases split into named checks, copies the peer completions own, a read loop through a pointer, and literals MSVC reads
…rence before a colon, and a nostr signer's result is nodiscard
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant